package com.ganlinux.pangoo.tools;

import com.ganlinux.pangoo.entity.AreaDivision;
import com.ganlinux.pangoo.entity.gaode.PoisInfo;
import com.ganlinux.pangoo.entity.gaode.RspAMapPlaceSearch;
import com.ganlinux.pangoo.entity.response.RspAddressSearchData;

import java.util.ArrayList;
import java.util.List;

public class AppUtil {
	public static RspAddressSearchData transRspAMapPlaceSearch2RspAddressSearchData(RspAMapPlaceSearch rspAMapPlaceSearch) {
		RspAddressSearchData rspAddressSearchData = new RspAddressSearchData();
		List<AreaDivision> areaDivisionList = new ArrayList<AreaDivision>();
		List<PoisInfo> poisInfos = rspAMapPlaceSearch.getPois();
		for (int i = 0; i < poisInfos.size(); i++) {
			AreaDivision addressInfo = new AreaDivision();
			addressInfo.setPlaceId(poisInfos.get(i).getId());
			addressInfo.setPlaceName(poisInfos.get(i).getName());
			
			addressInfo.setDistrictId(poisInfos.get(i).getAdcode());
			addressInfo.setDistrictName(poisInfos.get(i).getAdname());
			addressInfo.setCityId(poisInfos.get(i).getCitycode());
			addressInfo.setCityName(poisInfos.get(i).getCityname());
			addressInfo.setProvinceId(poisInfos.get(i).getPcode());
			addressInfo.setProvinceName(poisInfos.get(i).getPname());
			addressInfo.setCountryId("86");
			addressInfo.setCountryName("中国");
			addressInfo.setPlaceLocation(poisInfos.get(i).getLocation());
			areaDivisionList.add(addressInfo);
		}
		
		rspAddressSearchData.setAreaDivisionList(areaDivisionList);
		return rspAddressSearchData;
	}
	/*public static String getImgUrl(int user,int footprintid)
    {
        String img_filename = "http://o8ukte95k.bkt.clouddn.com/"+"user_"+user+"/footprint_"+footprintid+"/";
        return img_filename;
    }*/
	public static String getFileName(String url)
    {
        String s1 = url.replaceAll("http://o8ukte95k.bkt.clouddn.com/","");

        return s1;
    }
	public static String getImgTockenUrl(String user,int footprintid,String imgTocken)
    {
        String img_filename = "http://o8ukte95k.bkt.clouddn.com/"+"user_"+user+"/footprint_"+footprintid+"/"+imgTocken+"_";
        return img_filename;
    }
	
	public static String[] convertSuffixNameToArray(String str,int size){
        String[] strArray = new String[size];
        String[] array = str.split("\\|"); //拆分字符为"," ,然后把结果交给数组strArray
        int i;
        for (i = 0;i<array.length;i++){
            if (array[i].equals("")){
                strArray[i] = "jpg";
            }else{
                strArray[i] = array[i];
            }
        }
        for (int j = i;j<strArray.length;j++){
            strArray[j] = "jpg";
        }
        return strArray;
    }
}
